<?php 

function show_ip_info($ip)
{
	$url='http://freegeoip.net/csv/'.$ip;
	//打开文件，模式为只读；
	$fp=fopen($url, 'r');
	//从文件中读入一行，并且解析CSV字段
	$read=fgetcsv($fp);
	//关闭文件读取
	fclose($fp);
	set_time_limit(0);
	echo"<p> ip address info:
	ip:$ip<br>
	country:$read[2]<br>
	city,state:$read[5],$read[3]<br>
	latitude:$read[7]<br>
	longitude:$read[8]
	</p>";

}
//获取本机IP地址并查询信息
header('charset=utf-8');
echo "<p>you ip address infomations:</p>";

//$_SERVER['REMOTE_ADDR']获取本机IP地址函数
show_ip_info(@$_SERVEER['REMOTE_ADDR']);
echo "-------------------------------------------------------beautiful line---------------------------------------------";
echo "<form action='ip_check.php' method='post' accept-charset='utf-8'>
	<input type='text'  name='ip'/>
	<input type='submit' name='submit' value='search'>
</form>";
if(isset($_POST['ip']))
{
echo "you search ip address information is :";
show_ip_info(gethostbyname(@$_POST['ip']));
}

 ?>